/*
 * @Description: 该文件描述
 * @FilePath: \vue-web-template\src\utils\i18n.ts
 * @Author: Brian Brian@gmail.com
 * @Date: 2024-10-25 15:20:46
 * @LastEditors: Brian Brian@gmail.com
 * @LastEditTime: 2024-10-25 15:23:19
 */
import { storageLocal } from '@wxcn/utils'
import { createI18n } from 'vue-i18n'
import wxcnCfg from '../../wxcn.config.json'

export const languageDefault = storageLocal.getItem('__language__') || {
  label: '简体中文',
  value: 'zh-CN',
}

export const languageArr = [
  {
    label: '繁体中文',
    value: 'zh-TW',
  },
  {
    label: '简体中文',
    value: 'zh-CN',
  },
  // {
  //   label: "English",
  //   value: "en-US"
  // }
]

export async function i18n() {
  const locales = await fetch(`/locales/${wxcnCfg.identifier}.json?t=${Date.now()}`).then(res => res.json())
  return createI18n({
    legacy: false,
    locale: languageDefault.value,
    // fallbackLocale: "zh-CN",
    silentFallbackWarn: true,
    silentTranslationWarn: true,
    missingWarn: false,
    fallbackWarn: false,
    messages: {
      'zh-CN': locales.zhCN,
      'zh-TW': locales.zhTW || {},
      'en-US': locales.enUS || {},
    },
  })
}
